<extend name="Public/layout" />

<block name="style">
    <link rel="stylesheet" href="__PUBLIC__/Home/mobile2/css/nickname.css"/>
</block>
<block name="script"></block>
<block name="body">
    <body>
    <div class="head">
        <img src="__PUBLIC__/Home/mobile2/images/nickname.png" alt=""/>
    </div>
    <form class="main" action="{:U('User/nickname')}">
        <div class="input">
            <i></i>
            <input class="JS-input" type="text" name="nickname" placeholder="设置昵称" class="nickname" onblur="test()" value="{$sso_nickname}" />
        </div>
        <div class="msg"></div>
        <input type="button" value="确认" class="btn" onclick="dosubmit();"/>
    </form>
    </body>
</block> 

<block name="foot_script">
    <script src="__PUBLIC__/Home/mobile2/js/jquery-1.8.2.min.js"></script>
    <script>
    function test(){
        $(".input span").remove();
        var nickname = $("input[name=nickname]").val();
        var myreg =/[`~!@#$%^&*()_+<>?:"{},.\/;'[\]]/im;
        var s=myreg.test(nickname);
        if(s){
            $(".input").append("<span class='wrong'></span>");
            $(".msg").html("昵称不合法，请不要输入特殊字符！");
        }else{
            $(".input").append("<span class='right'></span>");
            $(".msg").empty();
            $.ajax({
                url:"http://test.66play.com/api/visitor/checkNickname?nickname="+nickname+"",
                type:'get',
                dataType:'json',
                success:function(data){
                    $(".input span").remove();
                    if(data.code==200){
                        $(".input").append("<span class='right'></span>");
                    }else{
                        $(".input").append("<span class='wrong'></span>");
                    }
                    $(".msg").html(data.info);
                }
            });
        }

    }
    function dosubmit(){
        var redirect_url = '{$redirect_url}' || '/';
        $.ajax({
            url:$('form').attr('action'),
            data:$(".JS-input").serialize(),
            type:'post',
            dataType:'json',
            success:function(data){
                if(data.state < 0){
                    alert(data.info)
                    return;
                }else{
                    window.location.href= redirect_url;
                }
            }
        });
    }
    </script>
</block> 